<?php
/**
 * @Author:      lyt
 * @DateTime:    2016-01-29 10:03:39
 * @Description: 订单备货记录
 */
class ScsOutOrderController extends BaseController {

    /**
     * @Author:      lyt
     * @DateTime:    2016-01-29 10:12:46
     * @Description: 订单的备货记录
     */
    /**
     * @Author:      lyt
     * @DateTime:    2016-04-29 18:43:36
     * @Description: 更改名字的获取方式 更改查询适用缓存 添加 规格字段
     * 名字不用产品包的item名字 直接取耗材当前的 系列加 型号
     */
    public function showOutOrder(){
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'order_id' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $orders=Orders::find(Input::get('order_id'));
            if(is_null($orders)){
                $response = Lang::get("scs_error.order_notexiet_40000");
                break;
            }
            if($orders->shop_id!=$sc_user->shop_id){
                $response = Lang::get("scs_error.order_note_shop_error_40003");
                break;
            }
            $moo_list=MaintenanceOutOrder::where("order_id",$orders->order_id)->get();
            // $arr=DB::select("SELECT moo.*,scf.name scf_name,s_scf.name s_scf_name,opi.num,opi.item_name opi_item_name,opbi.num opbi_num,opbi.item_name opbi_item_name,opns.`name`   opns_name,opns.num opns_num,si.model,sins.model sins_model,sins.brand_name,sins.series_name,sins.name sins_name,sins.unit sins_unit,ss.name,s_s.name s_s_name,sser.name ss_name,sb.brand_name sb_name,sser.unit FROM `maintenance_out_order` moo
            //         LEFT JOIN order_product_item opi on opi.id=moo.product_item_id
            //         LEFT JOIN order_product_base_item opbi on opbi.id=moo.product_item_id
            //         left join order_product_non_standard opns on opns.id=moo.product_item_id
            //         left join supply_item si on si.id=moo.item_id
            //         left join supply_item_non_standard sins on sins.id=moo.item_id
            //         left join supply_subject ss on si.subject=ss.id
            //         left join supply_subject s_s on sins.subject=s_s.id
            //         left join supply_series sser on sser.id=si.series_id
            //         left join supply_brand sb on sb.id=si.brand_id
            //         left join statistical_classification scf on scf.id=si.st_classifi_id
            //         left join statistical_classification s_scf on s_scf.id=sins.st_classifi_id
            //         where  moo.order_id=?",array($orders->order_id));
            $temp_arr=array();
            // var_dump($arr);
            // exit;
            foreach ($moo_list as $_a) {
                $temp_name=$subject=$model=$series_name=$brand_name=$unit=$specification="";
                // switch ($_a->product_type) {
                //     case 'promotion':
                //             $temp_name=$_a->opi_item_name; 
                //         break;
                //     case 'base':
                //             $temp_name=$_a->opbi_item_name;
                //         break;
                //     case 'non_standard':
                //            $temp_name=$_a->opns_name;
                //         break;
                // }
                $c=DB::select("select sum((number-return_numer)*tax_purchase_price) as number from maintenance_out_item where order_out_id=?",array($_a->id));
                // if($_a->type===0){
                    $item_info=SupplyItem::getCacheItemInfo($_a->item_id);
                    $temp_name=$item_info->name; 
                    $scf_name=$item_info->scf_name;
                    $subject=$item_info->subject_name;
                    $model=$item_info->model;
                    $series_name=$item_info->series_name;
                    $brand_name=$item_info->brand_name;
                    $unit=$item_info->unit;
                    $specification=$item_info->specification;
                // }else{
                //     $item_info=SupplyItemNonStandard::getCacheItemInfo($_a->item_id);
                //     $temp_name=$item_info->series_name.' '.$item_info->model; 
                //     $scf_name=$item_info->scf_name;
                //     $subject=$item_info->subject_name;
                //     $model=$item_info->model;
                //     $series_name=$item_info->series_name;
                //     $brand_name=$item_info->brand_name;
                //     $unit=$item_info->unit;
                //     $specification=$item_info->specification;
                // }
                $temp_arr[]=array(
                    "id"=>$_a->id,
                    "shop_id"=>$_a->shop_id,
                    "status"=>$_a->status,
                    "type"=>$_a->type,
                    "product_type"=>$_a->product_type,
                    "number"=>$_a->number,
                    "return_number"=>$_a->return_number,
                    "name"=>$temp_name,
                    "subject"=>$subject,
                    "scf_name"=>$scf_name,
                    "model"=>$model,
                    "series_name"=>$series_name,
                    "brand_name"=>$brand_name,
                    "unit"=>$unit,
                    "specification"=>$specification,
                    "supply_amount"=>$c[0]->number,
                    "item_name"=>$item_info->name,
                );
            }
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("count"=>sizeof($temp_arr),"out_orders"=>$temp_arr));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "showOutOrder", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-03-30 11:15:15
     * @Description: 用于显示订单的退货信息
     */
    public function showReturnOrder(){
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'order_id' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $orders=Orders::find(Input::get('order_id'));
            if(is_null($orders)){
                $response = Lang::get("scs_error.order_notexiet_40000");
                break;
            }
            if($orders->shop_id!=$sc_user->shop_id){
                $response = Lang::get("scs_error.order_note_shop_error_40003");
                break;
            }

            $mro_list=MaintenanceReturnOrder::where("order_id",$orders->order_id)->get();
            // $arr=DB::select("SELECT
            //         mro.*, opi.num,
            //         scf.name scf_name,s_scf.name s_scf_name,
            //         opi.item_name opi_item_name,
            //         opbi.num opbi_num,
            //         opbi.item_name opbi_item_name,
            //         opns.`name` opns_name,
            //         opns.num opns_num,
            //         si.model,
            //         sins.model sins_model,
            //         sins.brand_name,
            //         sins.series_name,
            //         sins. NAME sins_name,
            //         sins.unit sins_unit,
            //         ss.name,
            //         s_s.name s_s_name,
            //         sser.name ss_name,
            //         sb.brand_name sb_name,
            //         sser.unit
            //     FROM
            //         `maintenance_return_order` mro
            //     LEFT JOIN order_product_item opi ON opi.id = mro.product_item_id
            //     LEFT JOIN order_product_base_item opbi ON opbi.id = mro.product_item_id
            //     LEFT JOIN order_product_non_standard opns ON opns.id = mro.product_item_id
            //     LEFT JOIN supply_item si ON si.id = mro.item_id
            //     LEFT JOIN supply_item_non_standard sins ON sins.id = mro.item_id
            //     LEFT JOIN supply_subject ss ON si. SUBJECT = ss.id
            //     LEFT JOIN supply_subject s_s ON sins. SUBJECT = s_s.id
            //     LEFT JOIN supply_series sser ON sser.id = si.series_id
            //     LEFT JOIN supply_brand sb ON sb.id = si.brand_id
            //     left join statistical_classification scf on scf.id=si.st_classifi_id
            //     left join statistical_classification s_scf on s_scf.id=sins.st_classifi_id
            //     where  mro.order_id=?",array($orders->order_id));
            $temp_arr=array();
            // var_dump($arr);
            // exit;
            foreach ($mro_list as $_a) {
                $temp_name=$subject=$model=$series_name=$brand_name=$unit=$specification="";
                // if($_a->type===0){
                    $item_info=SupplyItem::getCacheItemInfo($_a->item_id);
                    $temp_name=$item_info->name; 
                    $scf_name=$item_info->scf_name;
                    $subject=$item_info->subject_name;
                    $model=$item_info->model;
                    $series_name=$item_info->series_name;
                    $brand_name=$item_info->brand_name;
                    $unit=$item_info->unit;
                    $specification=$item_info->specification;
                // }else{
                //     $item_info=SupplyItemNonStandard::getCacheItemInfo($_a->item_id);
                //     $temp_name=$item_info->series_name.' '.$item_info->model; 
                //     $scf_name=$item_info->scf_name;
                //     $subject=$item_info->subject_name;
                //     $model=$item_info->model;
                //     $series_name=$item_info->series_name;
                //     $brand_name=$item_info->brand_name;
                //     $unit=$item_info->unit;
                //     $specification=$item_info->specification;
                // }
                $temp_arr[]=array(
                    "id"=>$_a->id,
                    "shop_id"=>$_a->shop_id,
                    "status"=>$_a->status,
                    "type"=>$_a->type,
                    "product_type"=>$_a->product_type,
                    "number"=>$_a->number,
                    "name"=>$temp_name,
                    "subject"=>$subject,
                    "scf_name"=>$scf_name,
                    "model"=>$model,
                    "series_name"=>$series_name,
                    "brand_name"=>$brand_name,
                    "unit"=>$unit,
                    "specification"=>$specification,
                    "item_name"=>$item_info->name,
                );
            }
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("count"=>sizeof($temp_arr),"out_orders"=>$temp_arr));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "getProductPackages", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      zwh
     * @DateTime:    2016-1-29 13:50:19
     * @Description: 修改备货记录状态
     */
    public function updateOutStatus(){
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'order_id' => 'required',
                'ids'      => 'required'
            )
            );
        $ids=json_decode(Input::get('ids'));
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $orders=Orders::find(Input::get('order_id'));
            if(is_null($orders)){
                $response = Lang::get("scs_error.order_notexiet_40000");
                break;
            }
            if($orders->shop_id!=$sc_user->shop_id){
                $response = Lang::get("scs_error.order_note_shop_error_40003");
                break;
            }
            $response=MaintenanceOutOrder::updateMaintenanceOutOrderStatus($ids,Input::get('order_id'));
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "updateOutStatus", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    /**
     * @Author:      zwh
     * @DateTime:    2016-3-5 10:33:32
     * @Description: 订单的退货
     */
    public function returnOutOrder(){
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'moo_ids' => 'required',
                'order_id' => 'required'
            )
            );
        $moo_ids=json_decode(Input::get('moo_ids'),1);
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $orders=Orders::find(Input::get('order_id'));
            if(is_null($orders)){
                $response = Lang::get("scs_error.order_notexiet_40000");
                break;
            }
            if($orders->order_type==1){
                if(!in_array($orders->status,Orders::$serviceStart)){//订单状态是正确
                    $response = Lang::get("scs_error.order_status_error_40029");
                    break;
                }
            }else{
                if($orders->status!=1411){//订单状态是正确
                    $response = Lang::get("scs_error.order_status_error_40029");
                    break;
                }
            }  
            $op=OrderPay::where("order_id",$orders->order_id)->whereIn("status",array(0,1,5,7))->first();      
            if($op){//订单状态是否为服务结束状态
                $response = Lang::get("scs_error.order_pay_record_40112");
                break;
            }
            if($orders->shop_id!=$sc_user->shop_id){
                $response = Lang::get("scs_error.order_note_shop_error_40003");
                break;
            }
            $response=MaintenanceReturnOrder::returnOrders($moo_ids,Input::get('order_id'),$sc_user->shop_id);
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "returnOutOrder", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-10-24 11:14:07
     * @Description: 订单的一键退库
     */
    public function onekeyReturnOutOrder(){
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'moo_ids' => 'required',
                'order_id' => 'required'
            )
            );
        $moo_ids=json_decode(Input::get('moo_ids'),1);
        $response = array('code' => 0, 'msg' => 'ok','result'=>array('order_id'=>Input::get('order_id')));
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $orders=Orders::find(Input::get('order_id'));
            if(is_null($orders)){
                $response = Lang::get("scs_error.order_notexiet_40000");
                break;
            }
            if($orders->order_type==1){
                if(!in_array($orders->status,Orders::$serviceStart)){//订单状态是正确
                    $response = Lang::get("scs_error.order_status_error_40029");
                    break;
                }
            }else{
                if($orders->status!=1411){//订单状态是正确
                    $response = Lang::get("scs_error.order_status_error_40029");
                    break;
                }
            }         
            $op=OrderPay::where("order_id",$orders->order_id)->whereIn("status",array(0,1,5,7))->first();      
            if($op){//订单状态是否为服务结束状态
                $response = Lang::get("scs_error.order_pay_record_40112");
                break;
            }   
            if($orders->shop_id!=$sc_user->shop_id){
                $response = Lang::get("scs_error.order_note_shop_error_40003");
                break;
            }
            $response=MaintenanceReturnOrder::onekeyReturnOutOrder($moo_ids,Input::get('order_id'),$sc_user);
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "onekeyReturnOutOrder", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-10-24 14:07:42
     * @Description: 订单的一键出库
     */

    public function  onekeyOutOrder(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'ids'=>"required",
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.station_args_error_31001");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            $ids = json_decode(Input::get('ids'),1);
            if (count($ids) != count(array_unique($ids))) {
                $response = Lang::get("scs_error.order_out_error_40070");
                break;
            }
            $out_order_arr=array();
            foreach ($ids as $_id) {
                $date_id=explode(":",$_id);
                $moo=MaintenanceOutOrder::find($date_id[0]);
                if(is_null($moo)||$moo->shop_id!=$sc_user->shop_id){
                    $response = Lang::get("scs_error.maintenance_out_order_notexit_60009");
                    break 2;
                }
                // if($moo->status!=0&&$moo->status!=1$moo->status!=2){
                //     $response = Lang::get("scs_error.maintenance_out_order_statuserror_60010");
                //     break 2;
                // }
                if($moo->status===0){
                    $out_order_arr[]=$moo;
                }                
            }
            if(sizeof($out_order_arr)<=0){
                $response = Lang::get("scs_error.maintenance_out_order_empty_60015");
                break;
            }
            $orders=Orders::find($out_order_arr[0]->order_id);
            if(is_null($orders)){
                $response = Lang::get("scs_error.order_notexiet_40000");
                break;
            }
            if($orders->order_type==1){
                if(!in_array($orders->status,Orders::$serviceStart)){//订单状态是正确
                    $response = Lang::get("scs_error.order_status_error_40029");
                    break;
                }
            }else{
                if($orders->status!=1411){//订单状态是正确
                    $response = Lang::get("scs_error.order_status_error_40029");
                    break;
                }
            }            
            if($orders->shop_id!=$sc_user->shop_id){
                $response = Lang::get("scs_error.order_note_shop_error_40003");
                break;
            }
            if(MaintenanceInventoryList::isInventory($sc_user->shop_id)){
                $response = Lang::get("scs_error.data_inventory_isrun_61000");
                break;
            }
            $response=MaintenanceOutList::onekeyOutOrder($out_order_arr,$sc_user);
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "onekeyOutOrder", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      zwh
     * @DateTime:    2016-3-11 14:15:33
     * @Description: 按订单备货信息清单
     */
    public function orderInventory()
    {
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'book_time' => 'required',
            )
            );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            //所有符合的订单
            $order=Orders::where("status",1112)->where('shop_id',$sc_user->shop_id)->where('book_time',Input::get('book_time'))->select('order_id','name','phone','book_time','book_hour','car_brand_name','car_series_name','car_model_name','note','car_no')->get()->toArray();
            foreach($order as $k=>$v){

                //推广产品包包含的耗材
                $item1=OrderProductItem::where('order_id',$v['order_id'])
                ->leftJoin('supply_item',"supply_item.id","=","order_product_item.item_id")
                ->leftJoin('supply_brand','supply_item.brand_id','=','supply_brand.id')
                ->leftJoin('supply_subject','supply_item.subject','=','supply_subject.id')
                ->leftJoin('supply_series','supply_item.series_id','=','supply_series.id')
                ->where('type',1)
                ->select('order_product_item.id','order_product_item.order_id','order_product_item.item_id','order_product_item.item_name','order_product_item.amount','order_product_item.num','supply_item.model','supply_brand.brand_name','supply_series.name','supply_series.unit','supply_subject.name as s_name')
                ->get()->toArray();
                //基础产品包包含的耗材
                $item2=OrderProductBaseItem::where('order_id',$v['order_id'])
                ->leftJoin('supply_item',"supply_item.id","=","order_product_base_item.item_id")
                ->leftJoin('supply_brand','supply_item.brand_id','=','supply_brand.id')
                ->leftJoin('supply_subject','supply_item.subject','=','supply_subject.id')
                ->leftJoin('supply_series','supply_item.series_id','=','supply_series.id')
                ->select('order_product_base_item.id','order_product_base_item.order_id','order_product_base_item.item_id','order_product_base_item.item_name','order_product_base_item.amount','order_product_base_item.num','order_product_base_item.unit','supply_item.model','supply_brand.brand_name','supply_series.name','supply_subject.name as s_name')
                ->where('type',1)
                ->where('item_type',0)
                ->get()->toArray();
                $item3=OrderProductBaseItem::where('order_id',$v['order_id'])
                ->leftJoin('supply_item_non_standard',"supply_item_non_standard.id","=","order_product_base_item.item_id")
                ->leftJoin('supply_subject','supply_item_non_standard.subject','=','supply_subject.id')
                ->select('order_product_base_item.id','order_product_base_item.order_id','order_product_base_item.item_id','order_product_base_item.item_name','order_product_base_item.amount','order_product_base_item.num','order_product_base_item.unit','supply_item_non_standard.model','supply_item_non_standard.brand_name','supply_item_non_standard.series_name','supply_subject.name as s_name')
                ->where('type',1)
                ->where('item_type',1)
                ->get()->toArray();
                $items=array_merge($item1,$item2,$item3);
                $arr=array();
                foreach($items as $item){
                    if(isset($arr[$item['item_id']])){
                        $arr[$item['item_id']]['num']+=$item['num'];
                    }else{
                        $arr[$item['item_id']]=$item;
                    }
                }
                foreach($arr as $val){
                    $arr1[]=$val;
                }
                $order[$k]['items']=$arr1;
            }
            $response['result']=array('inventory_info'=>$order);
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "orderInventory", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      zwh
     * @DateTime:    2016-3-11 14:15:33
     * @Description: 按耗材备货信息清单
     */
    public function supplyInventory()
    {
        $validator = Validator::make(Input::all(),
            array(
                'token'    => 'required',
                'book_time' => 'required',
            )
            );
        $response = array('code' => 0, 'msg' => 'ok');
        do{
            if($validator->fails()) {
                $response = Lang::get("scs_error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $sc_user=$this->verificationSCSUserToken(Input::get("token"),$response);
            if(is_null($sc_user)){
                break;
            }
            //所有符合的订单
            $order=Orders::where("status",1112)->where('book_time',Input::get('book_time'))->where('shop_id',$sc_user->shop_id)->select('order_id')->get()->toArray();
            $order_ids = array_column($order, 'order_id');
            $arr=array();

            //推广产品包包含的耗材
            $item1=OrderProductItem::whereIn('order_id',$order_ids)
            ->leftJoin('supply_item',"supply_item.id","=","order_product_item.item_id")
            ->leftJoin('supply_brand','supply_item.brand_id','=','supply_brand.id')
            ->leftJoin('supply_subject','supply_item.subject','=','supply_subject.id')
            ->leftJoin('supply_series','supply_item.series_id','=','supply_series.id')
            ->where('type',1)
            ->select('order_product_item.id','order_product_item.order_id','order_product_item.item_id','order_product_item.item_name','order_product_item.amount','order_product_item.num','supply_item.model','supply_brand.brand_name','supply_series.name','supply_series.unit','supply_subject.name as s_name')
            ->get()->toArray();

            //基础产品包包含的耗材
            $item2=OrderProductBaseItem::whereIn('order_id',$order_ids)
            ->leftJoin('supply_item',"supply_item.id","=","order_product_base_item.item_id")
            ->leftJoin('supply_brand','supply_item.brand_id','=','supply_brand.id')
            ->leftJoin('supply_subject','supply_item.subject','=','supply_subject.id')
            ->leftJoin('supply_series','supply_item.series_id','=','supply_series.id')
            ->select('order_product_base_item.id','order_product_base_item.order_id','order_product_base_item.item_id','order_product_base_item.item_name','order_product_base_item.amount','order_product_base_item.num','order_product_base_item.unit','supply_item.model','supply_brand.brand_name','supply_series.name','supply_subject.name as s_name')
            ->where('type',1)
            ->where('item_type',0)
            ->get()->toArray();
            $item3=OrderProductBaseItem::whereIn('order_id',$order_ids)
            ->leftJoin('supply_item_non_standard',"supply_item_non_standard.id","=","order_product_base_item.item_id")
            ->leftJoin('supply_subject','supply_item_non_standard.subject','=','supply_subject.id')
            ->select('order_product_base_item.id','order_product_base_item.order_id','order_product_base_item.item_id','order_product_base_item.item_name','order_product_base_item.amount','order_product_base_item.num','order_product_base_item.unit','supply_item_non_standard.model','supply_item_non_standard.brand_name','supply_item_non_standard.series_name','supply_subject.name as s_name')
            ->where('type',1)
            ->where('item_type',1)
            ->get()->toArray();
            $items=array_merge($item1,$item2,$item3);
            foreach($items as $item){
                if(isset($arr[$item['item_id']])){
                    $arr[$item['item_id']]['num']+=$item['num'];
                }else{
                    $arr[$item['item_id']]=$item;
                }
            }
            $inventory_info=array();
            foreach($arr as $val){
                $inventory_info[]=$val;
            }
            $response['result']=array('inventory_info'=>$inventory_info);
        }while(false);
        Log::info("info", array("system" => "scs" ,"event" => "supplyInventory", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

}